///*
// *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
// *
// *  Redistribution and use in source and binary forms, with or without
// *  modification, are permitted provided that the following conditions are met:
// *
// *  Redistributions of source code must retain the above copyright notice,
// *  this list of conditions and the following disclaimer.
// *  Redistributions in binary form must reproduce the above copyright
// *  notice, this list of conditions and the following disclaimer in the
// *  documentation and/or other materials provided with the distribution.
// *  Neither the name of the dreamlu.net developer nor the names of its
// *  contributors may be used to endorse or promote products derived from
// *  this software without specific prior written permission.
// *  Author: Chill 庄骞 (smallchill@163.com)
// */
//package com.plian.system.service.fr.bank.impl;
//
//import com.plian.Tools.BigDecimalUtil;
//import com.plian.Tools.CollectionUtil;
//import com.plian.Tools.StringUtil;
//import com.plian.system.dto.fr.bank.BankDepositDTO;
//import com.plian.system.entity.fr.bank.BankDeposit;
//import com.plian.system.mapper.fr.bank.BankDepositMapper;
//import com.plian.system.mybatis.base.BaseServiceImpl;
//import com.plian.system.service.fr.bank.IBankDepositService;
//import com.plian.system.vo.fr.bank.BankDepositVO;
//import com.plian.system.vo.report.HeaderVO;
//import com.plian.system.vo.report.ReportReturnVO;
//import com.plian.system.vo.report.ReportVO;
//import lombok.AllArgsConstructor;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.stereotype.Service;
//import org.springframework.transaction.annotation.Transactional;
//
//import java.math.BigDecimal;
//import java.util.ArrayList;
//import java.util.List;
//import java.util.Optional;
//
///**
// * 服务实现类
// *
// * @author
// * @since 2019-09-27
// */
//@Slf4j
//@Service
//@AllArgsConstructor
//public class BankDepositServiceImpl extends BaseServiceImpl<BankDepositMapper, BankDeposit> implements IBankDepositService {
//
//	@Override
//	@Transactional(rollbackFor=RuntimeException.class)
//	public boolean saveOrUpdate(BankDeposit bankDeposit) {
//		bankDeposit.setInitialDepositAmount(bankDeposit.getDepositAmount());
//		return super.saveOrUpdate(bankDeposit);
//	}
//
//	@Override
//	@Transactional(rollbackFor=RuntimeException.class)
//	public boolean deleteLogic(List<Long> ids) {
//		for (Long id : ids) {
//			BankDeposit bankDeposit = getById(id);
//			if (bankDeposit == null) {
//				return false;
//			}
//		}
//		return super.deleteLogic(ids);
//	}
//
//	@Override
//	public ReportReturnVO summaryList(BankDepositDTO bankDepositDTO) {
//		List<BankDepositVO> data = baseMapper.summaryList(bankDepositDTO);
//		List<BankDepositVO> results = new ArrayList<>();
//		if (CollectionUtil.isNotEmpty(data)){
//			int totalCount = 0;
//			BigDecimal totalBalance = new BigDecimal(0);
//			int subtotalCount = 0;
//			BigDecimal subtotalBalance = new BigDecimal(0);
//			String lastTopGroupId = "";
//			for (int i = 0; i < data.size(); i++){
//				BankDepositVO result = data.get(i);
//				if (StringUtil.isNotBlank(lastTopGroupId) && !lastTopGroupId.equals(result.getTopGroupId())){
//					BankDepositVO subtotal = new BankDepositVO();
//					subtotal.setTopGroupName("小计：" + subtotalCount);
//					subtotal.setDepositAmount(subtotalBalance);
//					results.add(subtotal);
//					subtotalCount = 1;
//					subtotalBalance = result.getDepositAmount();
//				}else {
//					subtotalCount++;
//					subtotalBalance = BigDecimalUtil.add(subtotalBalance, result.getDepositAmount());
//				}
//				lastTopGroupId = result.getTopGroupId();
//				totalCount++;
//				totalBalance = BigDecimalUtil.add(totalBalance, result.getDepositAmount());
//				result.setDepositTypeName(getDepositTypeName(result.getDepositType()));
//				results.add(result);
//				if (i == data.size() - 1){
//					BankDepositVO subtotal = new BankDepositVO();
//					subtotal.setTopGroupName("小计：" + subtotalCount);
//					subtotal.setDepositAmount(subtotalBalance);
//					results.add(subtotal);
//				}
//			}
//			BankDepositVO end = new BankDepositVO();
//			end.setTopGroupName("合计：" + totalCount);
//			end.setDepositAmount(totalBalance);
//			results.add(end);
//		}
//
//		ReportReturnVO reportReturnVO = new ReportReturnVO();
//
//		ReportVO reportVO = new ReportVO();
//
//		reportVO
//				.addHeader(HeaderVO.builder().key("topGroupName").title("所属集团").build())
//				.addHeader(HeaderVO.builder().key("bankAccount").title("账户号").build())
//				.addHeader(HeaderVO.builder().key("bankAccountName").title("账户名称").build())
//				.addHeader(HeaderVO.builder().key("depositBankAccount").title("分账号").build())
//				.addHeader(HeaderVO.builder().key("bankName").title("银行名称").build())
//				.addHeader(HeaderVO.builder().key("depositTypeName").title("用途").build())
//				.addHeader(HeaderVO.builder().key("depositAmount").title("存款").build())
//				.addHeader(HeaderVO.builder().key("maxRate").title("最高年化利率%").build())
//				.addHeader(HeaderVO.builder().key("minRate").title("最低年化利率%").build())
//				.addHeader(HeaderVO.builder().key("beginTime").title("开始时间").build())
//				.addHeader(HeaderVO.builder().key("endTime").title("结束时间").build())
//				.addHeader(HeaderVO.builder().key("realEndTime").title("实际到期日").build());
//		reportVO.setData(results);
//		reportReturnVO.setGrids(reportVO);
//		return reportReturnVO;
//	}
//
//	private String getDepositTypeName(Integer depositType){
//		if(Optional.ofNullable(depositType).isPresent()){
//			switch (depositType){
//				case 1:
//					return "活期";
//				case 2:
//					return "定期";
//				case 3:
//					return "保证金";
//				case 4:
//					return "协定";
//				case 5:
//					return "通知";
//				case 6:
//					return "借款";
//				case 7:
//					return "理财";
//				case 8:
//					return "结构性存款";
//				default:
//					return "";
//			}
//		}
//		return "";
//	}
//}
